<template>
	<view>
		<view class="dogner-form-item">
			<view class="donger-from-item-label">旧密码：</view>
			<view class="donger-from-item-obj"> <input class="uni-input" password focus placeholder="请输入旧密码" v-model="pwds.oldpwd" /></view>
		</view>
		<view class="dogner-form-item">
			<view class="donger-from-item-label">新密码：</view>
			<view class="donger-from-item-obj"> <input class="uni-input" password placeholder="请输入新密码" v-model="pwds.newpwd" /></view>
		</view>
		<view class="dogner-form-item">
			<view class="donger-from-item-label">新密码确认：</view>
			<view class="donger-from-item-obj"> <input class="uni-input" password placeholder="请再次输入新密码" v-model="pwds.newpwd2" /></view>
		</view>

		<view class="dogner-form-item" style="border-bottom-width: 0;">
			<button style="width: 100%;" type="primary" @click="changePwd()">保存</button>
		</view>

	</view>
</template>

<script>
	import userService from '@/api/user.js'
	export default {
		data() {
			return {
				pwds: {
					oldpwd: "",
					newpwd: "",
					newpwd2: "",
				}
			};
		},
		methods: {
			changePwd: function() {
				if (this.pwds.newpwd === this.pwds.newpwd2 && this.pwds.newpwd !== "") {
					userService.changePwd(this.pwds).then((res) => {

						console.log(JSON.stringify(res.data));
						uni.showToast({
							icon: "none",
							title: res.data.msg,
							duration: 2000
						});
						if (res.data.success) {
							uni.navigateTo({
								url: "/pages/ucenter/login"
							});
						}
					});
				} else {
					uni.showToast({
						icon: "none",
						title: "新密码不一致",
						duration: 2000
					});
				}
			}
		}
	}
</script>

<style>

</style>
